<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
		//$user_id=1;
        $get=" ".$oto."_cart.goods_id,".$oto."_cart.goods_num,".$oto."_cart.isSelected,".$oto."_goods.goodsImg,".$oto."_goods.goodsName,".$oto."_goods.shopPrice,".$oto."_cart.goods_attr,".$oto."_cart.goodss_attr_id,".$oto."_shops.shopId,".$oto."_shops.shopName,".$oto."_shops.shopImg,".$oto."_goods.goodsStock";
        $sql="select ".$get." from `".$oto."_cart`,`".$oto."_goods`,`".$oto."_shops` where ".$oto."_cart.userId='".$user_id."' and ".$oto."_cart.goods_id=".$oto."_goods.goodsId and ".$oto."_goods.shopId=".$oto."_shops.shopId order by ".$oto."_cart.shop_id ASC";
		//$sql="select * from `".$oto."_cart` where `userId`='".$user_id."' order by shop_id ASC";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$cart[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(!isset($cart))
		{

		}
		else
		{
			$max=count($cart);
			for($i=0;$i<$max;$i++)
			{
				$money=0;
				$attr_id=$cart[$i]['goodss_attr_id'];
				if($attr_id==false || $attr_id=='false')
				{
					$money=0;
				}
				else
				{
					$z_attr_money;
					$attr_id_list=explode(',',$attr_id);
					$attr_max=count($attr_id_list);
					for($j=0;$j<$attr_max;$j++)
					{
						$z_attr_id=$attr_id_list[$j];
						$sql="SELECT * FROM ".$oto."_goods_attributes where id='$z_attr_id'";
						$result=$db->query($sql);
						while($row=$result->fetch_assoc()){
							$z_attr_money[$j]=$row;//将取得的所有数据赋值给person_info数组
						}
						$money+=$z_attr_money[$j]['attrPrice'];
						if($z_attr_money[$j]['attrStock']<$cart[$i]['goodsStock']) $cart[$i]['goodsStock']=$z_attr_money[$j]['attrStock'];
					}
				}
				$cart[$i]['shuxing_money']=$money;
			}
		}
		echo json_encode($cart);
?>